home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
c
/
mail110
/
quit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-25
|
3KB
|
128 lines
//=========================================================
//
// quit.c
//
// void quit(int update)
//
//==========================================================
// $Id: quit.c,v 1.3 1994/02/25 13:34:54 gbj Exp user $
/*
$Log: quit.c,v $
* Revision 1.3 1994/02/25 13:34:54 gbj
* Tidy-up.
*
* Revision 1.2 1994/02/08 23:33:54 gbj
* First public release.
*
* Revision 1.1 1994/02/08 03:16:14 gbj
* Initial revision
*
*/
#include "mailer.h"
#include "utils.h"
static char buf[4096];
void quit(int update)
{
char iname[128], oname[128], *bp;
FILE *ifd, *ofd;
int ix, res;
if (!update) // Don't update mailbox if 'x' exit
return;
printf("\nUpdating mailbox, please wait...\n");
strcpy(iname, mailpath);
strcat(iname, "\\");
strcat(iname, user);
strcpy(oname, iname);
strcat(iname, ".txt");
strcat(oname, ".$$$");
ofd=NULL;
ifd=NULL;
ofd=fopen(oname, "wb");
if (ofd == NULL)
{
fprintf(stderr, "quit: Can't open %s\n", oname);
remove(oname);
return;
}
// Now update the mailbox, removing deleted messages
for (ix=0; ix <= maxmsgno; ix++)
{
if (!mailix[ix].dflag)
{
// Not deleted so copy it out
res=tmp_msg(ix, "quit.$$$", FALSE, TRUE);
if (res)
{
fprintf(stderr, "quit: Can't update mailbox %s\n",
iname);
if (ofd)
fclose(ofd);
remove ("quit.$$$");
remove(oname);
return;
}
ifd=fopen("quit.$$$", "rb");
if (ifd == NULL)
{
fprintf(stderr, "quit: Can't open quit.$$$\n");
if (ofd)
fclose(ofd);
remove("quit.$$$");
remove(oname);
return;
}
// tmp_msg does not copy the initial From ... line so
// create it now
sprintf(buf, "From %s %s\n",
mailix[ix].sender, mailix[ix].msgdate);
fputs(buf, ofd);
// And put out the new X-Status: line,
// don't check deleted flag as it can't be set or else
// I wouldn't be here (famous last words!)
sprintf(buf, "X-Status: %c \n",(mailix[ix].rflag ? 'Y' : ' '));
fputs(buf, ofd);
// Now put out the message from quit.$$$
bp=fgets(buf, 4095, ifd);
while (bp != NULL)
{
scaneol(buf);
strcat(buf, "\n");
// Drop old X-Status: line
if (strncmp(buf, "X-Status:", 9) != 0)
fputs(buf, ofd);
bp=fgets(buf, 4095, ifd);
}
fclose(ifd);
ifd=NULL;
remove("quit.$$$");
}
}
if (ifd)
fclose(ifd);
if (ofd)
fclose(ofd);
remove("quit.$$$");
remove(iname);
res=rename(oname, iname); // Rename $$$ to txt
if (res != 0)
{
perror("quit");
fprintf(stderr, "quit: Can't rename %s to %s\n", oname, iname);
fprintf(stderr, "quit: %s must be manually renamed!\n", oname);
}
return;
}